import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int limit = in.nextInt();
        int min = Integer.MAX_VALUE;
        int[] weight = new int[n];
        for (int i = 0; i < n; i++) {
            weight[i] = in.nextInt();
            min = Math.min(min, weight[i]);
        }
        int[] price = new int[n];
        for (int i = 0; i < n; i++) {
            price[i] = in.nextInt();
        }
        int[] dp = new int[limit + 1];
        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = limit; j >= 0; j -= 1) {
                int sub = j - weight[i];
                if (sub < 0) {
                    continue;
                }
                dp[j] = Math.max(dp[j], dp[sub] + price[i]);
                max = Math.max(max, dp[j]);
            }
        }
        System.out.println(max);
    }


}
